// 引入行为种类
import actionType from '../action/actionType'

import { notification } from 'antd'

const initState = {
	useDraging: false,
	useScaling: false,
	useMagneticPoint: false,
	useFreeDrawing: false,
}

export default function canvasReducer(state = initState, action) {
	switch (action.type) {
		case actionType.TOGGLE_DRAGING: {
			if (!state.useDraging && action.state) {
				notification.info({
					message: '温馨提示',
					description: '当使用拖拽时，最好与 磁性点 功能连用，以达到最佳效果',
				})
			}
			return {
				...state,
				useDraging: action.state,
			}
		}
		case actionType.TOGGLE_SCALING: {
			if (!state.useScaling && action.state) {
				notification.info({
					message: '温馨提示',
					description: '左键放大，右键缩小',
				})
			}
			return {
				...state,
				useScaling: action.state,
			}
		}
		case actionType.TOGGLE_FREE_DRAWING: {
			return {
				...state,
				useFreeDrawing: action.state,
			}
		}
		case actionType.TOGGLE_ERASE: {
			return {
				...state,
				useErasing: action.state,
			}
		}
		case actionType.TOGGLE_MAGNETIC_POINT: {
			return {
				...state,
				useMagneticPoint: action.state,
			}
		}
		// reset!!!
		case actionType.RESET_STORE: {
			return initState
		}
		default: {
			return state
		}
	}
}
